package com.da.javatest.leetCode;

import java.util.Arrays;

/**
 * @author chenlida
 * @date 2019/2/28 10:36
 * @description
 */
public class Code34 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Code34().searchRange(new int[] {1}, 1)));
    }

    public int[] searchRange(int[] nums, int target) {
        int[] r = new int[] {-1, -1};
        String s = Arrays.toString(nums).replace("]", ",").replace("[", " ");
        if (!s.contains(" " + target + ",")) {
            return r;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int n = nums[i];
            if (n == target) {
                if (count == 0) {
                    r[0] = i;
                    count++;
                } else {
                    count++;
                }
            }

            if (count != 0 && n != target) {
                break;
            }
        }
        r[1] = r[0] + count - 1;
        return r;
    }
}
